package chances.system.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
	@RequestMapping(value = "/{index}", method = RequestMethod.GET)
	public String index(HttpServletRequest httpServletRequest, Model model,@PathVariable("index") String index) {
		httpServletRequest.setAttribute("contextPath", httpServletRequest.getContextPath());

		return index;
	}
	
	/**
	 * 用户的展示页面
	 * @param httpServletRequest
	 * @param model
	 * @param userId
	 * @param page
	 * @return
	 */
	@RequestMapping(value = "/{parent}/{page}", method = RequestMethod.GET)
	public String page(HttpServletRequest httpServletRequest, Model model,@PathVariable("parent") String parent,@PathVariable("page") String page) {
		httpServletRequest.setAttribute("contextPath", httpServletRequest.getContextPath());

		if(page==null){
			page= "index";
		}
		return parent+"/"+page;
	} 
	
	@RequestMapping(value = "/{parent}/{folder}/{page}", method = RequestMethod.GET)
	public String folder(HttpServletRequest httpServletRequest, Model model,@PathVariable("parent") String parent,@PathVariable("folder") String folder,@PathVariable("page") String page) {
		if(page==null){
			page= "index";
		}
		httpServletRequest.setAttribute("contextPath", httpServletRequest.getContextPath());
		return parent+"/"+folder + "/"+page;
	} 
	
	/*
	 * 用于排除BootstrapDialog调用弹出页面的sitemesh装饰
	 */
	@RequestMapping(value = "/dialog/{parent}/{page}", method = RequestMethod.GET)
	public String dialogPage(HttpServletRequest httpServletRequest, Model model,@PathVariable("parent") String parent,@PathVariable("page") String page) {
		if(page==null){
			page= "index";
		}
		httpServletRequest.setAttribute("contextPath", httpServletRequest.getContextPath());
		return parent + "/"+page;
	} 
	
}
